package com.wxb.hello.activemq.service.impl;


import com.wxb.hello.activemq.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.support.JmsUtils;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;

/**
 * describe: 邮件服务接口实现类
 *
 * @author : 王校兵
 * @version : v1.0
 * @time : 2017/7/18  14:05
 */
@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSender mailSender;

    @Value("${mail.fromMail.addr}")
    private String from;

    /**
     * 发送简单的邮件仅仅包括文本或者发送html模板类型的邮件。
     * 发送HTML模板类型的邮件需要将html模板处理为String类型的信息
     *
     * @param to      发送的目标
     * @param subject 邮件的主题
     * @param content 邮件的文本内容
     */
    @Override
    public void sendSimpleMail(String to, String subject, String content) throws JMSException{

        System.out.println(to);
        System.out.println(subject);
        System.out.println(content);

        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);
    }

}
